import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '../components/login.vue'
import Pub_home from '../components/Pub_home'
import welcome from '../components/Public/Course/welcome'
import Teacher_home from '../components/Teacher_home'
import manage_Course from '../components/Curriculum/manage_Course'
import Manager_home from '../components/Admin_home'
import Check_user from '../components/Admin/Check_user'
import Course_home from "../components/Curriculum/Courseinfo/Course_home";
import Course_detail from "../components/Curriculum/Courseinfo/Course_detail";
import Curriculum_relation from "../components/Curriculum/Courseinfo/Curriculum_relation";
import References from "../components/Curriculum/Courseinfo/References";
import Pub_Coursehome from "../components/Public/Course/Pub_Coursehome";
import Pub_ref from "../components/Public/Course/Pub_ref";
import Pub_base from "../components/Public/Course/Pub_base";
import Pub_book from "../components/Public/Course/Pub_book";
import Pub_detail from "../components/Public/Course/Pub_detail";
import FundamentalInfo from "../components/Curriculum/Courseinfo/FundamentalInfo";
import Leader_home from "../components/Leader_home";
import manageProfession from "../components/Profession/manageProfession";
import Sub_Profession from "../components/Profession/Sub_Profession";
import Sub_info from "../components/Profession/Sub_info";
import Pub_Profession from "../components/Public/Pro/Pub_Profession";
import Pub_SubProfession from "../components/Public/Pro/Pub_SubProfession";
import manageSemester from "../components/Profession/manageSemester";
import Sub_Semester from "../components/Profession/Sub_Semester";
import Sub_Sinfo from "../components/Profession/Sub_Sinfo";
import Semester from "../components/Public/Pro/Semester";
import Pub_Course from "../components/Public/Course/Pub_Course";
import Pub_Course_Frame from "../components/Public/Course/Pub_Course_Frame";
import manage_indicator from "@/components/Profession/manage_indicator";
import indicator_info from "@/components/Profession/indicator_info";
import Error from "@/components/Error";
import TestSecurity from "@/components/TestSecurity";
Vue.use(VueRouter)

const routes = [

  { path: '/', redirect: '/login'},
  { path: '/login', component: login},
  { path: '/TestSecurity', component: TestSecurity},
  { path: '/Manager_home',
    component: Manager_home,
    children: [
      { path: '/Check_user', component: Check_user,meta: {requireAuth: true, roles: ['Manager']}},
      ],
    meta: {requireAuth: true, roles: ['Manager']}
    },
  { path: '/Teacher_home',component: Teacher_home,name:'Teacher',
    children: [
      { path: '/manageCourse',component: manage_Course,meta: {requireAuth: true, roles: ['Teacher']}},
    ],
    meta: {requireAuth: true, roles: ['Teacher']}
  },

  { path: '/Leader_home',component: Leader_home,
    children: [
      { path: '/manageProfession',component: manageProfession,meta: {requireAuth: true, roles: ['Leader']}},
      { path: '/manageSemester',component: manageSemester,meta: {requireAuth: true, roles: ['Leader']}},
      { path: '/manage_indicator',component: manage_indicator,meta: {requireAuth: true, roles: ['Leader']}},
      { path: '/indicator_info',component: indicator_info,meta: {requireAuth: true, roles: ['Leader']}}
    ],
    meta: {requireAuth: true, roles: ['Leader']}
  },
  { path: '/Sub_Semester',component: Sub_Semester,
    children: [
      { path: '/Sub_Sinfo',component: Sub_Sinfo,meta: {requireAuth: true, roles: ['Leader']}},
    ],
    meta: {requireAuth: true, roles: ['Leader']}
  },

  { path: '/Sub_Profession',component: Sub_Profession,
    children: [
      { path: '/Sub_info',component: Sub_info,meta: {requireAuth: true, roles: ['Leader']}},
    ],
    meta: {requireAuth: true, roles: ['Leader']}
    },

  { path: '/Pub_Course_Frame',component: Pub_Course_Frame,
    children: [
      { path: '/Pub_Course',component:Pub_Course,meta: {requireAuth: false, roles: ['Pub']}},
    ],
    meta: {requireAuth: false, roles: ['Pub']}
    },

  { path: '/Course_home',component: Course_home,
    children:[
      {name:'FundamentalInfo', path: '/FundamentalInfo', component: FundamentalInfo,meta: {requireAuth: true, roles: ['Teacher']}},
      {name:'Course_detail', path: '/Course_detail', component: Course_detail,meta: {requireAuth: true, roles: ['Teacher']}},
      {name:'Curriculum_relation', path: '/Curriculum_relation', component: Curriculum_relation,meta: {requireAuth: true, roles: ['Teacher']}},
      {name:'References', path: '/References', component: References,meta: {requireAuth: true, roles: ['Teacher']}},
    ],
    meta: {requireAuth: true, roles: ['Teacher']}
  },


  {name:'Pub_Coursehome', path: '/Pub_Coursehome', component: Pub_Coursehome,
    children:[
      {name:'Pub_ref', path: '/Pub_ref', component: Pub_ref,meta: {requireAuth: false, roles: ['Pub']}},
      {name:'Pub_base', path: '/Pub_base', component: Pub_base,meta: {requireAuth: false, roles: ['Pub']}},
      {name:'Pub_detail', path: '/Pub_detail', component: Pub_detail,meta: {requireAuth: false, roles: ['Pub']}},
      {name:'Pub_book', path: '/Pub_book', component: Pub_book,meta: {requireAuth: false, roles: ['Pub']}},
    ],
    meta: {requireAuth: false, roles: ['Pub']}
  },


  { path: '/Pub_home',component: Pub_home,
    children:[
      { path: '/welcome', component: welcome,meta: {requireAuth: false, roles: ['Pub']} },
      { path: '/Pub_Profession',component: Pub_Profession,meta: {requireAuth: false, roles: ['Pub']}},
      { path: '/Pub_SubProfession',component: Pub_SubProfession,meta: {requireAuth: false, roles: ['Pub']}},
      { path: '/Semester',component: Semester,meta: {requireAuth: false, roles: ['Pub']}},
    ],
    meta: {requireAuth: false, roles: ['Pub']}
  },
  {
    path: '/Error',component: Error,
    meta: {requireAuth: false}
  }

]

const router = new VueRouter({
  routes
})
// router.beforeEach((to, from, next) => {
//   //项目标题
//   if(to.meta.title){
//     document.title = to.meta.title
//   }
//
//   if(to.path==='/login'||to.path==='/welcome')return next();
//
//   //有问题
//
//   const tokenStr1=window.sessionStorage.getItem('token')
//   if (!tokenStr1){
//     return next('/login');
//   }
//   next()
// })
export default router
